package net.mihome.app.bean;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

/**
 * 动弹实体类
 * @author liux (http://my.oschina.net/liux)
 * @version 1.0
 * @created 2012-3-21
 * @changed 2014-01-21
 * @difference
 * 	1.添加语音动弹属性
 */
public class Tweet extends Entity{

	public final static String NODE_ID = "id";
	public final static String NODE_FACE = "portrait";
	public final static String NODE_BODY = "body";
	public final static String NODE_AUTHORID = "authorid";
	public final static String NODE_AUTHOR = "author";
	public final static String NODE_PUBDATE = "pubDate";
	public final static String NODE_COMMENTCOUNT = "commentCount";
	public final static String NODE_IMGSMALL = "imgSmall";
	public final static String NODE_IMGBIG = "imgBig";
	public final static String NODE_APPCLIENT = "appclient";
	public final static String NODE_START = "tweet";
	public final static String NODE_ATTACH = "attach";
	public final static int CLIENT_MOBILE = 2;
	public final static int CLIENT_ANDROID = 3;
	public final static int CLIENT_IPHONE = 4;
	public final static int CLIENT_WINDOWS_PHONE = 5;
	public final static int CLIENT_WECHAT=6;

    private List<Map<String,Object>> commentList;
	private String face;
	private String body;
	private String author;
	private int authorId;
	private int commentCount;
	private String pubDate;
    private int isTop;
	private String imgSmall;
    private String[] imgSmalls;
    private String[] imgBigs;
	private String imgBig;
	private String support_list;
	private List<File> imageFiles=new ArrayList<>();
	private File amrFile;// 语音
	private int appClient;
	private String attach;
	private int support;
    private User user;
	public int getAppClient() {
		return appClient;
	}
	public void setAppClient(int appClient) {
		this.appClient = appClient;
	}
	public List<File> getImageFiles() {
		return imageFiles;
	}
	public void setImageFiles(List<File> imageFiles) {
		this.imageFiles = imageFiles;
	}
	public File getAmrFile() {
		return amrFile;
	}
	public void setAmrFile(File amrFile) {
		this.amrFile = amrFile;
	}
	public String getImgSmall() {
		return imgSmall;
	}
	public void setImgSmall(String imgSmall) {
		this.imgSmall = imgSmall;
	}
	public String getImgBig() {
		return imgBig;
	}
	public void setImgBig(String imgBig) {
		this.imgBig = imgBig;
	}
	public String getFace() {
		return face;
	}
	public void setFace(String face) {
		this.face = face;
	}
	public String getBody() {
		return body;
	}
	public void setBody(String body) {
		this.body = body;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public int getAuthorId() {
		return authorId;
	}
	public void setAuthorId(int authorId) {
		this.authorId = authorId;
	}
	public int getCommentCount() {
		return commentCount;
	}
	public void setCommentCount(int commentCount) {
		this.commentCount = commentCount;
	}
	public String getPubDate() {
		return pubDate;
	}
	public void setPubDate(String pubDate) {
		this.pubDate = pubDate;
	}
	
	public String getAttach() {
		return attach;
	}
	public void setAttach(String attach) {
		this.attach = attach;
	}
	public static Tweet parse(Map map){
		Tweet tweet=new Tweet();
		Double idsDouble=(Double) map.get("id");
		tweet.setId(idsDouble.intValue());
		tweet.setAuthor((String)map.get("username"));
		tweet.setBody((String)map.get("text"));
		Double uid=(Double) map.get("uid");
		Double isTopD=(Double) map.get("is_top");
        tweet.setIsTop(isTopD.intValue());
		tweet.setAuthorId(uid.intValue());
		tweet.setFace((String)map.get("avatar"));
		String imgsString=(String)map.get("imgs");
		if(imgsString!=null){
			String[] imgs=imgsString.split(";");
			tweet.setImgSmall(imgsString);
			tweet.setImgBig(imgsString.replace("thumb/", ""));
            //设置图片组
            tweet.setImgSmalls(imgs);
            String[] bigImags=new String[imgs.length];
            for(int i=0;i<imgs.length;i++){
                bigImags[i]=imgs[i].replace("thumb/", "");
            }
            tweet.setImgBigs(bigImags);
		}
		tweet.setPubDate((String)map.get("create_at"));
		tweet.setSupport_list((String) map.get("support_list"));
		Double commentCount=(Double) map.get("replay_num");
        Double supportNum=(Double)map.get("support");
        if(map.get("comment_list")!=null){
            List<Map<String, Object>> comments=(List<Map<String, Object>>) map.get("comment_list");
            Collections.sort(comments,new Comparator<Map<String, Object>>() {
                @Override
                public int compare(Map<String, Object> stringObjectMap, Map<String, Object> stringObjectMap2) {
                    Double id1= (Double) stringObjectMap.get("id");
                    Double id2= (Double) stringObjectMap2.get("id");
                    if(id1.compareTo(id2)>0){
                        return -1;
                    }else{
                        return 1;
                    }
                }
            });
            tweet.setCommentList(comments);
        }
        if(supportNum==null){
            supportNum=new Double(0);
        }
        if(map.get("mark_user")!=null){
            tweet.setUser(User.parse((Map) map.get("mark_user")));
        }
        tweet.setSupport(supportNum.intValue());
		tweet.setCommentCount(commentCount.intValue());
		return tweet;
	}

    public int getSupport() {
        return support;
    }

    public void setSupport(int support) {
        this.support = support;
    }

    public String getSupport_list() {
        return support_list;
    }

    public void setSupport_list(String support_list) {
        this.support_list = support_list;
    }

    public String[] getImgSmalls() {
        return imgSmalls;
    }

    public void setImgSmalls(String[] imgSmalls) {
        this.imgSmalls = imgSmalls;
    }

    public String[] getImgBigs() {
        return imgBigs;
    }

    public void setImgBigs(String[] imgBigs) {
        this.imgBigs = imgBigs;
    }

    public List<Map<String, Object>> getCommentList() {
        return commentList;
    }

    public void setCommentList(List<Map<String, Object>> commentList) {
        this.commentList = commentList;
    }

    public int getIsTop() {
        return isTop;
    }

    public void setIsTop(int isTop) {
        this.isTop = isTop;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}
